#include <unordered_map>
#include <vector>
using namespace std;

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int,int> my_map;
        for (int it=0;it<nums.size();it++)
        {
            if(my_map.find(target-nums[it])!=my_map.end())
            {
                return vector<int>{my_map[target-nums[it]],it};
            }
            my_map[nums[it]]=it;
        }
        return vector<int>{0,1};
    }
};

//2020.8.11 town 新添加
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int,int> umap;
        for(int i=0;i<nums.size();i++){
            umap.insert(make_pair(nums[i],i));
        }
        vector<int> res(2,-1);
        for(int i=0;i<nums.size();i++){
            auto iter=umap.find(target-nums[i]);
            if(iter!=umap.end()&&iter->second!=i){
                res[0]=i;
                res[1]=iter->second;
                return res;
            }
        }
        return res;
    }
};